package day20210712;

/**
 * 275. H 指数 II
 * 二份查找
 * @author lizy
 * @date 2021/07/12
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] a  = {1,3,5,7,9};
        System.out.println(solution.hIndex(a));
    }
    public int hIndex(int[] citations) {
        int n = citations.length;
        int left = 0, right = n - 1;
        while (left <= right) {
            int mid = left + (right - left) / 2;
            if (citations[mid] >= n - mid) {
                right = mid - 1;
            } else {
                left = mid + 1;
            }
        }
        return n - left;
    }
}
